﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Expand.Patterns.Command;
using SpellCaster3.Core;

namespace SpellCaster3.Commands
{
    public class SetButtonMacroPropertyCommand<T> : ICommand
    {
        private ButtonMacro _Receiver;

        private string _Property;
        private T _LastValue;
        private T _NewValue;
        private HomeForm _Form;

        public SetButtonMacroPropertyCommand(HomeForm form, ButtonMacro receiver, string property, T value)
        {
            _Receiver = receiver;;
            _Property = property;
            _Form = form;

            _NewValue = value;
            _LastValue = (T)_Receiver.GetType().GetProperty(property).GetValue(_Receiver, null);
        }

        public object Receiver
        {
            get { return _Receiver; }
        }

        public void Execute()
        {
            _Receiver.GetType().GetProperty(_Property).SetValue(_Receiver, _NewValue, null);
            _Form.Icons[_Receiver].SyncWithButtonMacro(_Receiver);
        }

        public void UnExecute()
        {
            _Receiver.GetType().GetProperty(_Property).SetValue(_Receiver, _LastValue, null);
            _Form.Icons[_Receiver].SyncWithButtonMacro(_Receiver);
        }
    }
}
